package com.lucky.utils;

public class Result {
    private int code;//状态码
    private boolean flag;//是否成功
    private String message;//提示信息

    private  Object data;//返回的数据

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Result() {
    }

    /**
     * 增、删、改返回的数据类型
     * @param code
     * @param flag
     * @param message
     */
    public Result(int code, boolean flag, String message) {
        this.code = code;
        this.flag = flag;
        this.message = message;
    }

    /**
     * 查询返回的类型
     * @param code
     * @param flag
     * @param message
     * @param data
     */
    public Result(int code, boolean flag, String message, Object data) {
        this.code = code;
        this.flag = flag;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功
     * @return
     */
    public static Result ok(String msg){
        return new Result(StatusCode.OK,true,msg,null);
    }

    /**
     * 成功
     * @return
     */
    public static Result ok(Object data){
        return new Result(StatusCode.OK,true,null,data);
    }

    /**
     * 失败
     * @param data
     * @return
     */
    public static Result fail(String msg,Object data){

        return new Result(StatusCode.ERROR,false,msg,data);
    }

    /**
     * 失败
     * @param
     * @return
     */
    public static Result fail(String msg){

        return new Result(StatusCode.ERROR,false,msg,null);
    }



}
